package com.project.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.template.dto.SysUserDTO;
import com.project.template.entity.Banner;
import com.project.template.entity.Posts;
import com.project.template.entity.SecondHandGoods;
import com.project.template.mapper.BannerMapper;
import com.project.template.mapper.PostsMapper;
import com.project.template.service.BannerService;
import com.project.template.service.PostsService;
import com.project.template.utils.UserThreadLocal;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 功能：
 * 作者：lhp
 */
@Service
public class PostsServiceImpl extends ServiceImpl<PostsMapper, Posts> implements PostsService {
    @Override
    public Page<Posts> page(Map<String, Object> query, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Posts> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Posts::getId);
        //条件模糊查询
//        if(query.get("name")!=null){
//            wrapper.like(Posts::getId,query.get("name"));
//        }
        return page(new Page<>(pageNum,pageSize),wrapper);
    }
    @Override
    public Posts getPosts(int id){
        LambdaQueryWrapper<Posts> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Posts::getId,id);
        return baseMapper.selectOne(wrapper);
    }
    @Override
    public Page<Posts> mypage(Map<String, Object> query, Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Posts> wrapper = new LambdaQueryWrapper<>();
        SysUserDTO currentUser = UserThreadLocal.getCurrentUser();
        wrapper.eq(Posts::getPostId,currentUser.getId());
        return page(new Page<>(pageNum,pageSize),wrapper);
    }
}
